﻿using _02_Configuration.Extensions.Ison;
using Microsoft.Extensions.Configuration;

namespace Microsoft.Extensions.Configuration
{
    public static class IsonConfigurationExtensions
    {
        public static IConfigurationBuilder AddJsonUrl(this IConfigurationBuilder builder, string url)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentException(nameof(url));
            }

            return builder.Add(new IsonConfigurationSource(url));
        }

        public static IConfigurationBuilder AddJsonUrl(this IConfigurationBuilder builder, Action<IsonConfigurationSource> configure)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var source = new IsonConfigurationSource();
            configure(source);//执行用户配置
            return builder.Add(source);
        }
    }
}
